<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::prefix('v1')->name('api.v1.')->namespace('Api\V1')->group(function() {
    Route::middleware('throttle:' . config('api.rate_limits.sign'))
        ->group(function () {
            // 用户注册
            Route::post('users', 'UsersController@store')
                ->name('users.store');

            Route::post('weapp/authorizations', 'AuthorizationsController@weappStore')->name('weapp.authorizations.login'); // 小程序登录
            Route::post('weapp/users', 'UsersController@weappStore')->name('weapp.users.store');    // 小程序注册

            Route::put('authorizations/current', 'AuthorizationsController@update')->name('authorizations.update');
            // 删除token
            Route::delete('authorizations/current', 'AuthorizationsController@destroy')->name('authorizations.destroy');
        });

    Route::middleware('throttle:' . config('api.rate_limits.access'))
        ->group(function () {
            // 版本号
            Route::get('version', function() {
                    return 'this is version v1';
                })->name('version');

            Route::get('region', 'RegionController@index')->name('region.index');   // 省份地址

            Route::get('region/{id}', 'RegionController@children')->name('region.children');    // 下级地址

            // 推文
            Route::get('article_cates', 'ArticlesController@cate_index')->name('article_cate.index');
            Route::get('articles', 'ArticlesController@index')->name('article.index');
            Route::get('articles/{article}', 'ArticlesController@show')->name('article.show');

            Route::get('home', 'HomeController@home')->name('home');

            Route::middleware('auth:api')->group(function(){
                // 收货地址
                Route::post('user_addresses', 'UserAddressesController@store')->name('user_address.store');
                Route::get('user_addresses', 'UserAddressesController@index')->name('user_address.index');
                Route::get('user_addresses/default', 'UserAddressesController@default')->name('user_address.default');
                Route::get('user_addresses/{address}', 'UserAddressesController@show')->name('user_address.show');
                Route::put('user_addresses/{address}', 'UserAddressesController@update')->name('user_address.update');
                Route::delete('user_addresses/{address}', 'UserAddressesController@delete')->name('user_address.delete');

                Route::post('articles/replies/{article}', 'ArticleRepliesController@store')->name('article.reply.store');   // 推文回复

                Route::post('orders', 'OrderController@store')->name('order.store');    // 预约
                Route::get('orders', 'OrderController@index')->name('order.store');
                Route::get('orders/complete/{order}', 'OrderController@complete')->name('order.complete');
                Route::get('orders/close/{order}', 'OrderController@close')->name('order.close');

                Route::get('user', 'UsersController@me')
                        ->name('user.show');    // 用户数据
            });
        });
});
